//
//  FSCalendarHeaderView.m
//  Test
//
//  Created by 樊盛 on 2019/5/8.
//  Copyright © 2019年 樊盛. All rights reserved.
//

#import "FSCalendarHeaderView.h"
#import "CalendarMacroHeader.h"

@interface FSCalendarHeaderView()

@property (nonatomic, strong) UILabel *mouLabel;

@end

@implementation FSCalendarHeaderView

- (instancetype)initWithFrame:(CGRect)frame dateFormatter:(NSDateFormatter *)dateFormatter {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = Color_CalendarHeaderView_Bg;
        [self drawWeekHeaderViewWithFrame:frame dateFormatter:dateFormatter];
    }
    return self;
}

- (void)drawWeekHeaderViewWithFrame:(CGRect)frame dateFormatter:(NSDateFormatter *)dateFormatter {
    [self addSubview:self.mouLabel];
    NSMutableArray *days = [[dateFormatter shortStandaloneWeekdaySymbols] mutableCopy];
    NSString *firstDay = days.firstObject;
    [days removeObjectAtIndex:0];
    [days addObject:firstDay];
    for (int i = 0; i < days.count; i++) {
        CGFloat width = frame.size.width / days.count;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(i * width, 30, width, 30)];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = Color_Text_CalendarHeaderView_Label;
        label.font = Font_CalendarHeaderLabel;
        label.text = [self getChineseWeek:days[i]];
        [self addSubview:label];
    }
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(16, 59, kScreenWidth - 32, 1)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:lineView];
}

- (void)setTitleMouth:(NSString *)mouth {
    self.mouLabel.text = mouth;
}

- (NSString *)getChineseWeek:(NSString *)week {
    if ([week isEqualToString:@"Sun"]) {
        return @"周日";
    } else if ([week isEqualToString:@"Mon"]) {
        return @"周一";
    } else if ([week isEqualToString:@"Tue"]) {
        return @"周二";
    } else if ([week isEqualToString:@"Wed"]) {
        return @"周三";
    } else if ([week isEqualToString:@"Thu"]) {
        return @"周四";
    } else if ([week isEqualToString:@"Fri"]) {
        return @"周五";
    } else {
        return @"周六";
    }
}

- (NSString *)getChineseMonth:(NSString *)month {
    if ([month isEqualToString:@"Jan"]) {
        return @"一月";
    } else if ([month isEqualToString:@"Feb"]) {
        return @"二月";
    } else if ([month isEqualToString:@"Mar"]) {
        return @"三月";
    } else if ([month isEqualToString:@"Apr"]) {
        return @"四月";
    } else if ([month isEqualToString:@"May"]) {
        return @"五月";
    } else if ([month isEqualToString:@"Jun"]) {
        return @"六月";
    } else if ([month isEqualToString:@"Jul"]) {
        return @"七月";
    } else if ([month isEqualToString:@"Aug"]) {
        return @"八月";
    } else if ([month isEqualToString:@"Sep"]) {
        return @"九月";
    } else if ([month isEqualToString:@"Oct"]) {
        return @"十月";
    } else if ([month isEqualToString:@"Nov"]) {
        return @"十一月";
    } else {
        return @"十二月";
    }
}

- (UILabel *)mouLabel {
    if (!_mouLabel) {
        _mouLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
        _mouLabel.textAlignment = NSTextAlignmentCenter;
        _mouLabel.textColor = Color_Text_CalendarHeaderView_Label;
        _mouLabel.font = [UIFont systemFontOfSize:15];
        _mouLabel.backgroundColor = [UIColor redColor];
    }
    return _mouLabel;
}

@end
